﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;


namespace SeCompUFSCarWeb.Evento
{
    public class Mail
    {
        public static bool Send(string email, string message, string subject)
        {
            SmtpClient smtpClient = new SmtpClient();
            MailMessage ms = new MailMessage();

            try
            {
                MailAddress fromAddress = new MailAddress("secomp@ufscar.br", "SeComp UFSCar");

                // To address collection of MailAddress
                ms.To.Add(email);
                ms.From = fromAddress;
                ms.Subject = subject;

                //Body can be Html or text format
                //Specify true if it  is html message
                ms.IsBodyHtml = true;

                // Message body content
                ms.Body = message;

                //Solving Certificate errors
                ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, 
                    X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

                // Send SMTP mail
                smtpClient.Send(ms);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}